<?php

    
    if($_POST) {
        $but = $_POST['bot'];
                $data = array("butClickd" => $but);
                $data = json_encode($data);
                $file = fopen("jsondata.txt", "w");
                fwrite($file, $data);
                fclose($file);
        }
?>
<!DOCTYPE HTML>
<html>
    <head>
        <title>Phone</title>
        <link  type="text/css" rel="stylesheet" href="css.css"/>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
        <script type="text/javascript">
        //1 up, 2 left, 3 down, 4 right
                
            $('document').ready(function() {
                $('#up').click(function() {
                    sendEvent(1);
                })
                
                $('#down').click(function() {
                    sendEvent(3);
                })
                
                $('#left').click(function() {
                    sendEvent(2);
                })
                
                $('#right').click(function() {
                    sendEvent(4);
                })
                
                function sendEvent(action) {
                    $('#buttens').hide();
                    $('#updating').show();
                    $.ajax({
                        type: "POST",
                        url: "phone.php",
                        data: "bot=" + action,
                        success: function(msg) {
                            $('#buttens').show();
                            $('#updating').hide();
                        }
                    })
                }
            })
        </script>
    </head>
    <body>
        <div id="top">
            <span>:::::The box game:::</span>
        </div>
        <div id="buttens">
        <div id="updating">Please wait...</div>
        <button id="up">Up</button>
        <button id="down">Down</button><br />
        <button id="left">Left</button>
        <button id="right">Right</button>
        <div id="event"></div>
        </div>
    </body>
</html>